package com.forlove.app.qselect.friend.adapter;

import android.content.Context;
import android.graphics.Color;
import android.widget.TextView;

import com.forlove.app.R;
import com.forlove.app.common.base.mvp.presenter.IBasePresenter;
import com.forlove.app.common.utils.StringUtils;
import com.forlove.app.common.utils.ViewUtils;
import com.forlove.app.common.widget.CircleImageView;
import com.forlove.app.common.widget.recyview.BaseRecyclerAdapter;
import com.forlove.app.common.widget.recyview.ViewHolder;
import com.forlove.app.qselect.friend.entity.MineFriendEntity;

import java.util.List;

/**
 * 选择指定人选为本题的答题人选
 * Created by yjl on 2017/11/11.
 */

public class SetAnswerFriendAdapter extends BaseRecyclerAdapter<MineFriendEntity> {
    private String queryStr;

    public SetAnswerFriendAdapter(Context context, int itemView, List<MineFriendEntity> mDatas, IBasePresenter presenter) {
        super(context, itemView, mDatas, presenter);
    }

    public void setQueryStr(String queryStr) {
        this.queryStr = queryStr;
    }

    @Override
    protected void convertView(ViewHolder holder, final MineFriendEntity entity, int position) {
        CircleImageView photo = holder.getView(R.id.cv_image_portrait);
        if (basePresenter != null) {
            basePresenter.loadImageView(mContext, photo, entity.img, R.mipmap.image_mine_friend_avatar);
        }
        TextView userName = holder.getView(R.id.tv_friend_name);
        userName.setText(entity.getAvaliableName());
        if (StringUtils.isNotEmpty(queryStr)
                && StringUtils.isNotEmpty(entity.getAvaliableName())
                && entity.getAvaliableName().contains(queryStr)) {
            int start = entity.getAvaliableName().indexOf(queryStr);
            ViewUtils.customTextColor(userName, Color.parseColor("#2ac2b9"), start, start + queryStr.length());
        }
        //TODO 具体展示问题
        if (entity.isFromContacts || StringUtils.isNotEmpty(entity.mConcatName)) {
            holder.setText(R.id.tv_from, "通讯录好友");
        } else {
            holder.setText(R.id.tv_from, "圈一圈好友");
        }
        if (entity.isSelected) {
            holder.setVisible(R.id.iv_checkout, true);
            holder.getConvertView().setBackgroundResource(R.drawable.bg_add_friends_click);
        } else {
            holder.setVisible(R.id.iv_checkout, false);
            holder.getConvertView().setBackgroundResource(R.drawable.bg_add_friends_gray);
        }
    }
}
